package com.example.demo.controller;

import com.example.demo.common.Result;
import com.example.demo.dto.VehicleCreateDTO;
import com.example.demo.dto.VehicleGetDTO;
import com.example.demo.service.VehicleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("api/v1/car")
public class VehicleController {
    @Autowired
    private VehicleService vehicleService;

    @GetMapping
    public Result getCars(VehicleGetDTO vehicleGetDTO){
        return vehicleService.searchVehicleByIdAndType(vehicleGetDTO);
    }

    @GetMapping("/getAllId")
    public Result getAllCarIds(){
        return vehicleService.getAllCarIds();
    }

    @PostMapping
    public Result addCar(@RequestBody VehicleCreateDTO vehicleCreateDTO){
        return vehicleService.addVehicle(vehicleCreateDTO);
    }

    @DeleteMapping("/{id}")
    public Result deleteCar(@PathVariable("id") String id) {
        return vehicleService.deleteVehicleById(id);
    }

    @DeleteMapping("/batDelete")
    public Result deleteBat(@RequestBody String[] ids){
        System.out.println(ids.length);
        return vehicleService.batDelete(ids);
    }
}
